import java.util.Scanner;

/**
 * Created by loso on 2017/3/29.
 */
public class _wanmei_2017329Test2 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextLine()) {//注意while处理多个case
            String s = in.nextLine();
            String[] ss = s.split(",");
            int[] values = new int[ss.length ];
            for (int i = 0; i < ss.length; i++) {
                    values[i] = Integer.parseInt(ss[i]);
            }
            int v = Integer.parseInt(in.nextLine());

            int[] out = new int[v+1];
            for (int i = 0; i < out.length; i++) {
                out[i] = -1;
            }
            for (int i = 1; i < out.length; i++) {
                int min = -1;
                for (int j = 0; j < values.length; j++) {
                    if (i-values[j] >0){
                        if (out[i-values[j]] != -1){
                            //说明能得到
                            if (min == -1){
                                min = out[i-values[j]]+1;
                            }else{
                                min = min<out[i-values[j]]+1?min:out[i-values[j]]+1;
                            }
                        }
                    }
                      else if(i==values[j]){
                        min = 1;
                    }
                }
                out[i] = min;
            }
            System.out.println(out[v]);
        }

    }
}
